package com.whu.waterworks.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.dto.TempDataDto;
import com.whu.waterworks.model.Stationnumposition;
import com.whu.waterworks.model.TempData;
import com.whu.waterworks.service.StationnumpositionService;
import com.whu.waterworks.service.TempDataService;

public class GetAllTempData extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String waterPlantCode;
	
	private TempDataService tempDataService;
	private StationnumpositionService stationnumpositionService;
	
	private List<TempDataDto> tempDataDtos = null;

	

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		try {
			tempDataDtos = new ArrayList<>();
			System.out.println("*****GetAllTempData waterPlantCode="+waterPlantCode);
			List<TempData> tempDatas = tempDataService.getAllDatas(waterPlantCode);
			if(tempDatas!=null &&tempDatas.size()>0)
			{
				
				System.out.println("*****GetAllTempData tempDatas.size()="+tempDatas.size());
				for(TempData tempData:tempDatas)
				{
					TempDataDto tempDataDto = new TempDataDto();
					Stationnumposition stationnumposition = stationnumpositionService.findStationById(tempData.getId().getStationnum());
					System.out.println("*****GetAllTempData stationnumposition.getPositionname()="+stationnumposition.getPositionname());
					tempDataDto.setStationName(stationnumposition.getPositionname());
					tempDataDto.setStationCode(tempData.getId().getStationnum());
					tempDataDto.setTime(tempData.getId().getTime());
					tempDataDto.setType(tempData.getId().getType());
					tempDataDto.setValue(tempData.getValue());
					tempDataDtos.add(tempDataDto);
				}
			}
			System.out.println("*****GetAllTempData tempDataDtos.size()="+tempDataDtos.size());
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return super.execute();
	}

	
	public TempDataService getTempDataService() {
		return tempDataService;
	}

	public void setTempDataService(TempDataService tempDataService) {
		this.tempDataService = tempDataService;
	}


	


	public String getWaterPlantCode() {
		return waterPlantCode;
	}


	public void setWaterPlantCode(String waterPlantCode) {
		this.waterPlantCode = waterPlantCode;
	}


	

	public StationnumpositionService getStationnumpositionService() {
		return stationnumpositionService;
	}


	public void setStationnumpositionService(StationnumpositionService stationnumpositionService) {
		this.stationnumpositionService = stationnumpositionService;
	}


	public List<TempDataDto> getTempDataDtos() {
		return tempDataDtos;
	}


	public void setTempDataDtos(List<TempDataDto> tempDataDtos) {
		this.tempDataDtos = tempDataDtos;
	}
}
